package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfDecrypt;
import com.yuandian.api.management.validate.UpdateFlag;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.management.service.ConfDecryptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 解密方式配置表-Controller
 * @author zfsn
 * @date 2023-3-23
 */
@Api(tags = "专属指标详情配置-解密方式")
@RestController
@RequestMapping("/decrypt")
public class ConfDecryptController {

	@Autowired
	private ConfDecryptService confDecryptService;


	/**
	 * 通过主键查询数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，支持批量查询")
	@GetMapping("/{ids}")
	public R<List<ConfDecrypt>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confDecryptService.listByIds(idList));
	}

	/**
	 * 分页查询
	 * @param confDecrypt 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "resourceCode", value = "服务资源编码", paramType = "query", required = true, dataType = "String"),
			@ApiImplicitParam(name = "size", value = "页大小", paramType = "query", required = true, dataType = "Long"),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "isAsc", value = "排序的方向值只能是 desc 或者 asc", paramType = "body", required = true, dataType = "String")
	})
	@PostMapping
	public R<Page<ConfDecrypt>> listPage(@RequestBody @ApiIgnore ConfDecrypt confDecrypt) {
		return R.ok(confDecryptService.listPage(confDecrypt));
	}

	/**
	 * 新增数据
	 * @param confDecrypt 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@SysLog("新增解密方式配置表数据")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "source", value = "密文来源", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "matchRegular", value = "匹配串", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "ecryptMode", value = "加密模式", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "ecryptBit", value = "数据块(加密位数)", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "offset", value = "偏移量", paramType = "body", required = true, example = "1", dataType = "Integer"),
			@ApiImplicitParam(name = "keyword", value = "关键字(密文关键字)", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "ecryptAlg", value = "加密算法", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "fillValue", value = "填充值", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "secretKey", value = "密码(秘钥)", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "encodeType", value = "密文编码方式", paramType = "body", required = true, dataType = "String")
	})
	@PostMapping("/save")
	public R<Boolean> save(@RequestBody @ApiIgnore ConfDecrypt confDecrypt) {
		return R.ok(confDecryptService.save(confDecrypt));
	}

	/**
	 * 通过主键更新数据
	 * @param confDecrypt 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@SysLog("更新解密方式配置表数据")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "主键", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "source", value = "密文来源", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "matchRegular", value = "匹配串", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "ecryptMode", value = "加密模式", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "ecryptBit", value = "数据块(加密位数)", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "offset", value = "偏移量", paramType = "body", required = true, example = "1", dataType = "Integer"),
			@ApiImplicitParam(name = "keyword", value = "关键字(密文关键字)", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "ecryptAlg", value = "加密算法", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "fillValue", value = "填充值", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "secretKey", value = "密码(秘钥)", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "encodeType", value = "密文编码方式", paramType = "body", required = true, dataType = "String")
	})
	@PutMapping
	public R<Boolean> updateById(@RequestBody @ApiIgnore @Validated(UpdateFlag.class) ConfDecrypt confDecrypt) {
		return R.ok(confDecryptService.updateById(confDecrypt));
	}

	/**
	 * 通过主键删除数据
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@SysLog("删除解密方式配置表数据")
	@DeleteMapping("/delete/{ids}")
	public R<Boolean> removeById(@PathVariable("ids") List<Integer> ids){
		return R.ok(confDecryptService.removeByIds(ids));
	}

}
